package com.hevs.samplewebapp.client.bean;

import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;

/**
 * Enum Class of time laps
 * <p> The goal is to map indexes to name for the time laps</p>
 * @author Matthias Hurni
 * @date 26.03.2012
 */
public enum TimeLaps {

	/**
	 * Last day
	 */
	DAILY(0,"Today"),

	/**
	 * Last week
	 */
	WEEKLY(1,"Last Seven days"),

	/**
	 * Last month
	 */
	MONTHLY(2,"Last month"),

	/**
	 * Last three month
	 */
	Quarterly(3,"Last three months"),

	/**
	 * Last three month
	 */
	Custom(4,"Custom");

	/**
	 * numerical representation of the time laps
	 */
	private int level;

	/**
	 * name of the time laps
	 */
	private final String name;

	/**
	 * Map of all the time laps
	 */
	private static final Map<Integer,TimeLaps> lookup=new HashMap<Integer,TimeLaps>();

	// ----------------------------------------------------------------------------
	// Constructor
	// ----------------------------------------------------------------------------

	/**
	 * Constructor of the time laps to map a name to a number
	 * @param level
	 * 	numerical representation of the time laps
	 * @param name
	 * 	name of the time laps
	 */
	private TimeLaps(int level,String name)
	{
		this.level=level;
		this.name=name;
	}

	// ----------------------------------------------------------------------------
	// Methods
	// ----------------------------------------------------------------------------

	/**
	 * Method to create time laps with level and name
	 */
	static
	{
		for(TimeLaps c:EnumSet.allOf(TimeLaps.class))
			lookup.put(c.getLevel(),c);
	}

	/**
	 * Returns the integer value of this level (greater value, later in the day)
	 */
	public int getLevel()
	{
		return level;
	}

	/**
	 * Returns the name of this level
	 */
	public String getName()
	{
		return name;
	}

	/**
	 * Returns the size of the enum
	 */
	public static int getSize()
	{
		return TimeLaps.values().length;
	}

	/**
	 * Returns the Category Enum
	 */
	public static TimeLaps get(int level)
	{
		return lookup.get(level);
	}

	public String toString()
	{
		return name;
	}
}